package cn.hackcloud.concurrency.activeobject;

import cn.hackcloud.concurrency.future.Future;

import java.util.Map;

public class FindOrderDetailsMessage extends MethodMessage {
    public FindOrderDetailsMessage(Map<String, Object> params, OrderService orderService) {
        super(params, orderService);
    }

    @Override
    public void execute() {
        //1
        Future<String> realFuture = orderService.findOrderDetails((Long) params.get("orderId"));
        ActiveFuture<String> activeFuture = (ActiveFuture<String>) params.get("activeFuture");
        final String result;
        try {
            //2
            result = realFuture.get();
            //3
            activeFuture.finish(result);
        } catch (InterruptedException e) {
            activeFuture.finish(null);
        }

    }
}
